package com.panda.web.controller.product;

import java.util.List;
import java.util.Arrays;

import com.panda.common.core.domain.R;
import com.panda.web.domain.vo.product.ProOpenidVO;
import com.panda.web.domain.vo.product.ProductAdvantage;
import com.panda.web.domain.vo.product.ProductOpenidVO;
import com.panda.web.entity.product.OpenidProduct;
import com.panda.web.service.product.IProductService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.panda.web.utils.pageutils.PageResult;

import com.panda.common.annotation.Log;
import com.panda.common.core.controller.BaseController;
import com.panda.common.core.domain.AjaxResult;
import com.panda.common.enums.BusinessType;
import com.panda.web.domain.dto.ProductDTO;
import com.panda.web.domain.vo.product.ProductVO;


/**
 * 产品
 * Controller
 *
 * @author cpanda
 * @date 2025-03-03
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/product")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ProductController extends BaseController {
    @Autowired
    IProductService productService;

    /**
     * 查询产品列表
     */
    @GetMapping("/list")
    public PageResult<ProductVO> List(ProductDTO dto,
                                      @RequestParam("pageNum") Integer pageNum,
                                      @RequestParam("pageSize") Integer pageSize) {
        //返回分页信息
        PageResult<ProductVO> voList = productService.PageList(dto, pageNum, pageSize);
        return voList;
    }

    @GetMapping("/list/All")
    public R  ListAll(ProductDTO dto) {
        //返回分页信息
        List<ProductVO> voList = productService.ListAll(dto);
        return R.ok(voList, "ok");
    }

    /**
     * 查询产品 列表 无分页
     */
    @GetMapping("/choiceList")
    public R choiceList(ProductDTO dto) {
        List<ProductVO> voList = productService.choiceList(dto);
        return R.ok(voList, "ok");
    }

    /**
     * 获取该用户购买了哪些产品
     */
    @GetMapping("/cp/{openid}")
    public R getOpenidByProduct(@PathVariable String openid) {
        return R.ok(productService.getOpenidByProduct(openid), 200, "ok");
    }

    /**
     * 获取该用户购买了哪些产品
     */
    @GetMapping("/cp/ai/{openid}")
    public R getOpenidAiByProduct(@PathVariable String openid) {
        return R.ok(productService.getOpenidAiByProduct(openid), 200, "ok");
    }


//    /**
//     * 用户购买产品列表
//     */
//    @GetMapping("/openProList")
//    public PageResult<ProOpenidVO> productList(ProductDTO dto,
//                                        @RequestParam("pageNum") Integer pageNum,
//                                        @RequestParam("pageSize") Integer pageSize) {
//        //返回分页信息
//        PageResult<ProOpenidVO> voList = productService.proOpenidList(dto,pageNum,pageSize);
//        return voList;
//    }



    /**
     * 获取产品详细信息
     */
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId) {
        return AjaxResult.success(productService.selectById(productId));
    }

    /**
     * 新增产品
     */
    @Log(title = "产品", businessType = BusinessType.INSERT)

    @PostMapping
    public AjaxResult add(@RequestBody ProductDTO dto) {
        return toAjax(productService.insert(dto));
    }

    /**
     * 修改产品
     */
    @Log(title = "产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductDTO dto) {
        return toAjax(productService.updateProductById(dto));
    }

    /**
     * 删除产品
     */
    @Log(title = "产品", businessType = BusinessType.DELETE)

    @DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds) {
        return toAjax(productService.removeByProductIds(Arrays.asList(productIds)));
    }

    /**
     * 试用套餐
     */
    @GetMapping("/trialStatus/{openid}")
    public AjaxResult trialStatus(@PathVariable String openid) {
        return toAjax(productService.trialStatus(openid));
    }


    /**
     * 手动添加用户套餐
     */
    @PostMapping("/sdProduct")
    public R sdProduct(@RequestBody OpenidProduct openidProduct){
      return R.ok(productService.sdProduct(openidProduct),200,"ok");
    }
    /**
     * 查询用户拥有套餐
     */
    @GetMapping("/getUserProduct")
    public R getUserProduct(OpenidProduct openidProduct){
        return R.ok(productService.getUserProduct(openidProduct),200,"ok");
    }
    /**
     * 关闭用户套餐
     */
    @PutMapping("/gbUserProduct")
    public R gbUserProduct(@RequestBody OpenidProduct openidProduct){
        return R.ok(productService.gbUserProduct(openidProduct),200,"ok");
    }
    /**
     * g根据用户登录openid
     */
    @GetMapping("openDay")
    public Long getTimeDay(String openid){
        Long count = productService.getDayOpenidProduct(openid);
       return  count;
    }


















































































































































































































































































































































































































































































}
